<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>练习</title>
    <style>
        #outer{
            width: 520px;
            background-color: #bfa;
            margin: 50px auto;
            text-align: center;
        }

        img{
            vertical-align: bottom;
            margin: 10px;
        }
    </style>
</head>
<body>

<div id="outer">
    <img src="img/1.jpg" alt="冰棍">
    <button id="last">上一张</button>
    <button id="next">下一张</button>
</div>
<script>
    var last = document.getElementById('last');
    last.onclick = function () {
        var img = document.getElementsByTagName('img');
            // alert('nihao')
        var reg = /img\/(\d)\.jpg$/;
        var num = img[0].src.match(reg)[1];
        // alert(img[0].src);
      // alert(num);
        for (i=num;i<6;i++){
           img[0].src = function () {
               var result = img/i.jpg;
               alert(result);
                return result+"";
           };
        }

    }
    var next = document.getElementById('next');
    next.onclick = function () {

    }
</script>
</body>
</html>